package h0725;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 水仙花数
 * @date 2024/7/25 17:29
 */
public class DaffodilNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); //位数
        int index = sc.nextInt();
        int res = getRes(n, index);
        System.out.println(res);
        System.out.println(isDaffodil(153));
    }

    private static int getRes(int n, int index) {
        if (n < 3 || n > 7) return -1; //不合法

        List<Integer> list=new ArrayList<>();
        int start = (int) Math.pow(10, n-1);
        int end = (int) Math.pow(10, n );
        for (int i = start; i < end; i++) {
            if (isDaffodil(i)){
                list.add(i);
            }
        }
        if (index>list.size()){
            return list.get(list.size()-1);
        }else {
            return list.get(index);
        }
    }

    private static boolean isDaffodil(int a) {
        int sum=0;
        int num=a;
        //TODO 有可能中间是0或者末尾是0
        while (num>0){
            int remain=num%10;
            sum+=remain*remain*remain;
            num/=10;
        }
        return sum==a;
    }
}
